package com.datacloud.controller;
import com.datacloud.service.InventoryManageService;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by QKY on 2016/10/18.
 * 库存管理
 */
@Controller
@RequestMapping("inventory")
public class InventoryManageController  {
    @Autowired
    InventoryManageService inventoryManageService;
    //fastjson中对日期的序列化定义
    private static SerializeConfig serializeConfig = new SerializeConfig();
    private static String dateFormat;
    static {
        dateFormat = "yyyy-MM-dd HH:mm:ss";
        serializeConfig.put(Date.class, new SimpleDateFormatSerializer(dateFormat));
    }
//    库存盘点
    @RequestMapping(value = "/inventoryTire",method = RequestMethod.GET,produces = "application/json; charset=gbk")
    @ResponseBody
    public String findInventoryTire(@RequestParam("stockid")int stockid){
        JSONObject result = inventoryManageService.getInventoryTire(stockid);
        return JSONObject.toJSONString(result,serializeConfig);
    }

    /**
     * 翻新盘点
     */
    @RequestMapping(value = "/recappedTire",method = RequestMethod.GET,produces = "application/json; charset=gbk")
    @ResponseBody
    public String findRecappedTire(@RequestParam("stockid")int stockid){
        JSONObject result = inventoryManageService.getRecappedTire(stockid);
        return JSONObject.toJSONString(result,serializeConfig);
    }
    /**
     * 获取所有的处理意见
     */
    @RequestMapping(value = "/findAllMemo",method = RequestMethod.GET,produces = "application/json; charset=gbk")
    @ResponseBody
    public String findAllMemoInfo(){
        JSONObject result = inventoryManageService.findAllMemoInfo();
        return JSONObject.toJSONString(result,serializeConfig);
    }

    /**
     * 获取翻新轮胎
     * @param stockid
     * @return
     */
    @RequestMapping(value = "/getRenovatedTyreByStockid",method = RequestMethod.GET,produces = "application/json; charset=gbk")
    public String getRenovatedTyreByStockid(@RequestParam("stockid") int stockid){

        JSONObject result=new JSONObject();
        result.put("success",true);
        result.put("data",inventoryManageService.getRenovatedTyreByStockid(stockid));
        result.put("msg","");
        return result.toJSONString();
    }

    /**
     * 获取配送轮胎
     * @param stockid
     * @return
     */
    @RequestMapping(value = "/getDistributionTireByStockid",method = RequestMethod.GET,produces = "application/json; charset=gbk")
    public String getDistributionTireByStockid(@RequestParam("stockid") int stockid) {

        JSONObject result = new JSONObject();
        result.put("success",true);
        result.put("data", inventoryManageService.getDistributionTireByStockid(stockid));
        result.put("msg", "");
        return result.toJSONString();
    }

    /**
     * 轮胎出库
     * @param tireid
     * @param aimid
     * @param stockid
     * @return
     */
    @RequestMapping(value = "/tireOutgoing",method = RequestMethod.POST,produces =  "application/json; charset=gbk")
    @ResponseBody
    public String tireOutgoing(@RequestParam("tireid")int tireid,@RequestParam("aimid") int aimid,@RequestParam("stockid") int stockid){
        JSONObject result = new JSONObject();
        result.put("success",inventoryManageService.tireOutgoing( tireid,aimid,stockid));
        result.put("msg","");
        return result.toJSONString();
    }

    /**
     * 翻新轮胎入库
     * @param tirelist
     * @param stockid
     * @return
     */
    @RequestMapping(value = "/renovatedTire",method = RequestMethod.POST,produces =  "application/json; charset=gbk")
    @ResponseBody
    public String renovatedTire(List<String>tirelist, @RequestParam("stockid") int stockid){
        JSONObject result = new JSONObject();
        result.put("success",inventoryManageService.renovatedTire(tirelist,stockid));
        result.put("msg","");
        return result.toJSONString();
    }

    /**
     * 配送轮胎入库
     * @param tirelist
     * @param stockid
     * @return
     */
    @RequestMapping(value = "/distributionTire",method = RequestMethod.POST,produces =  "application/json; charset=gbk")
    @ResponseBody
    public String distributionTire(List<String>tirelist, @RequestParam("stockid") int stockid){
        JSONObject result = new JSONObject();
        result.put("success",inventoryManageService.distributionTire(tirelist,stockid));
        result.put("msg","");
        return result.toJSONString();
    }
}
